/**
 * Created by yangh on 2016/09/07.
 */
var main = {};
var myScroll;
(function ($) {
    main.init = function () {
        document.addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);
    };

    /**
     * @func move()
     * @desc 监听滚动条的位置，异步加载列表
     */
    function move() {
    	
      
        if (this.y < main.max - 80) {
        	
        	var url = path+"/score/market/goods/listJson"; 
        	  
            $("#tip").hide();
            $("#loading").show();
 

        	$.get(url,{"sortno":sortno},function(data){
        		
        		if(data.content!=''){
		        		 var html = "";
		                 for (var i = 0; i < data.content.length; i++) {
		                     html +='<li>\
		                         <a href='+path+'/score/market/goods/details/'+data.content[i].id+' class="goods">\
		                         <div class="goodsImg">\
		                         <img src="'+data.content[i].picurl+'" alt="">\
		                         </div>\
		                         <h4>'+data.content[i].name+'</h4>\
		                     <p class="describe">'+data.content[i].title+'</p>\
		                     <span class="integral">'+(data.content[i].price*score)+'积分<span class="left"></span> </span>\
		                         </a>\
		                         </li>';
		                 } 
		                 sortno = data.content[data.content.length-1].id;//最后一个ID
		                 $(".goodsList").append(html);
        		}
        	});
        	 
            
            this.refresh();
            main.max = this.maxScrollY;
            console.log(main.max);

            $("#loading").hide();
            $("#tip").show();
        }
    }

    /**
     * @func main.scroll()
     * @desc 配置iscroll插件
     */
    main.scroll = function () {
        myScroll = new IScroll("#wrapper", {probeType: 3, mouseWheel: true, click: true, preventDefault: false});

        main.max = myScroll.maxScrollY;
        /*console.log(main.max);*/

        myScroll.on("scroll", move);
    }
})(jQuery);

main.init();

window.onload = function () {
    main.scroll();
};